#include "CameraInterface.h"

CameraInterface::CameraInterface (Camera& camera) : _camera (camera)
{

}

void CameraInterface::mouseDown (Button button, int x, int y)
{
	glm::ivec2 curMouseLoc (x, y);
	_mouseButtonState[button] = true;
	_lastMouseLoc = curMouseLoc;
}

void CameraInterface::mouseUp (Button button, int x, int y)
{
	glm::ivec2 curMouseLoc (x, y);
	_mouseButtonState[button] = false;
	_lastMouseLoc = curMouseLoc;
}

void CameraInterface::mouseDrag (int x, int y)
{
	glm::ivec2 curMouseLoc (x, y);
	if (_mouseButtonState[B_LEFT]) {
		float dx = (float)curMouseLoc[0] - (float)_lastMouseLoc[0];
		float dy = (float)curMouseLoc[1] - (float)_lastMouseLoc[1];
		_camera.rotateCamera (-dx / 500.0f * 180.0f, Camera::H);
		_camera.rotateCamera (-dy / 500.0f * 180.0f, Camera::V);
	}
	_lastMouseLoc = curMouseLoc;
}

void CameraInterface::mouseWheel (int count)
{
	if (count < 0)
		_camera.moveFar (-(float)count * 1.5f);
	else
		_camera.moveNear ((float)count * 1.5f);
}

void CameraInterface::keyDown (char key)
{
	switch (key) {
	case 'w':
		_camera.moveViewPointReletedToCamera (glm::vec3 (0, 0, -0.5));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (0, 0, -10));
		break;
	case 's':
		_camera.moveViewPointReletedToCamera (glm::vec3 (0, 0, 0.5));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (0, 0, 10));
		break;
	case 'a':
		_camera.moveViewPointReletedToCamera (glm::vec3 (-0.5, 0, 0));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (-10, 0, 0));
		break;
	case 'd':
		_camera.moveViewPointReletedToCamera (glm::vec3 (0.5, 0, 0));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (10, 0, 0));
		break;
	case 'x':
		_camera.moveViewPointReletedToCamera (glm::vec3 (0, -0.5, 0));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (0, -10, 0));
		break;
	case 'z':
		_camera.moveViewPointReletedToCamera (glm::vec3 (0, 0.5, 0));
		//_camera.setViewpoint (_camera.getViewpoint () + glm::vec3 (0, 10, 0));
		break;
	}
}